package com.example.finaltool.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.finaltool.model.CmmFunctionConfigCheck;
import com.example.finaltool.model.db.CmmFunctionConfig;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author dengbw
 */
@Mapper
public interface CmmFunctionConfigMapper extends BaseMapper<CmmFunctionConfig> {

    @Insert("INSERT INTO `cmm_function_cofig`(`user_type`, `nh_type`, `gb_type`, `is_cz`, `subject`, `out_url`, `images`, `is_mr`, `create_user_id`, `create_time`, `modify_user_id`, `modify_time`, `tenant_id`,`default_images`, sort_no, ext_flag, sub_tenant_id) VALUES (#{userType}, #{nhType}, #{gbType}, #{isCz}, #{subject}, #{outUrl}, #{images}, #{isMr}, 2, NOW(), 2, NOW(), #{corpId}, #{defaultImage}, #{sortNo}, #{extFlag}, #{subTenantId})")
    void save(Integer userType, Integer nhType, Integer gbType, Integer isCz, String subject, String outUrl,
              String images, Integer isMr, String corpId, String defaultImage, Integer sortNo, Boolean extFlag, Long subTenantId);

    @Select("SELECT DISTINCT c.default_images as default_images, c.user_type as user_type, c.nh_type as nh_type, c.sort_no as sort_no FROM cmm_function_cofig c WHERE c.tenant_id = #{corpId} and c.sub_tenant_id = #{subId}")
    List<CmmFunctionConfigCheck> queryExistFunction(String corpId, Long subId);

    @Update("UPDATE cmm_function_cofig SET default_images=images WHERE tenant_id = #{corpId} and sub_tenant_id= #{subId}")
    void updateDefaultImage(String corpId, Long subId);

    @Select("SELECT DISTINCT sub_tenant_id from cmm_function_cofig where tenant_id = #{corpId}")
    List<Long> queryExistSubIds(String corpId);
}
